package com.wfw.feichat.controller;

import com.google.common.collect.Lists;
import com.wfw.feichat.common.ResponseCode;
import com.wfw.feichat.common.ServerResponse;
import com.wfw.feichat.entity.Chatmsg;
import com.wfw.feichat.service.ChatmsgService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author: wfw
 * @date: 2019/05/24
 */
@RestController
@RequestMapping("/msg")
public class ChatmsgController {
    @Autowired
    private ChatmsgService chatmsgService;

    @RequestMapping("/getUnReadMsgList")
    public ServerResponse getUnReadMsgList(String acceptUserId) {
        if (StringUtils.isBlank(acceptUserId)) {
            return ServerResponse.buildErrorRC(ResponseCode.LACK_PARAM);
        }
        List<Chatmsg> chatmsgList = chatmsgService.getChatmsgListByAccepUid(acceptUserId);

        if (chatmsgList == null || chatmsgList.size() <= 0) {
            return ServerResponse.buildOk(Lists.newArrayList());
        }

        return ServerResponse.buildOk(chatmsgList);
    }
}
